package com.citybox.web;

import com.citybox.shared.utils.StringUtils;
import com.citybox.shared.utils.ip.IPUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

@Slf4j
@SpringBootApplication
@ComponentScan({"com.citybox"})
public class CityBoxApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(CityBoxApplication.class, args);

        Environment env = application.getEnvironment();
        String ip = IPUtils.getIpAddress();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        String active = env.getProperty("spring.profiles.active");
        log.info("当前运行环境：{}", active);
        log.info("\n\t----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Local:   \thttp://localhost:" + port + path + "/" + "\n\t" +
                "Knife4j: \thttp://" + ip + ":" + port + (StringUtils.isNotBlank(path) ? path : "") + "/doc.html  \n\t" +
                "Swagger: \thttp://" + ip + ":" + port + (StringUtils.isNotBlank(path) ? path : "") + "/swagger-ui/index.html  \n\t" +
                "----------------------------------------------------------");
    }
}